/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utility.CustomTag;

import ExampleBean.ExampleItem;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;


/**
 *
 * @author Tran Nguyen Anh Tu
 */
public class ShowitemTag extends SimpleTagSupport{
    //TAG PARAM - GETTER&SETTER
    private int row;
    private int col;
    private String id; //CSS ID
    private ArrayList item;

    public void setItem(ArrayList item) {
        this.item = item;
    }  
    public void setCol(int col) {
        this.col = col;
    }
    public void setRow(int row) {
        this.row = row;
    } 
    public void setId(String id) {
        this.id = id;
    }  
    //HANDLE FUNCTION
    public void doTag()
            throws JspException, IOException
    {
        JspWriter out = getJspContext().getOut();
        String blank_icon_path="Resources/blank-icon.jpg";
        String book_icon_path="Resources/BookCoverImages/";
        int itemcount=item.size();
        int count=0;
        
        //LOOP
        for(int i=0;i<row;i++)
        {
            out.println("<tr id="+id+">");
            for(int j=0;j<col;j++)
            {
                if(itemcount==count) break;
                ExampleItem book = (ExampleItem)item.get(count);
                out.println("<td>");
                out.print("<a href=\"ContentControllerServlet\">");
                out.println("<img src="+book_icon_path+"img"+j+".jpg"+" alt=\"Header image\" width=\"50\" height=\"75\" border=\"0\" /></a>");
                out.println("<br/>");
                out.println(book.getIname()+"<br/>");
                out.println(book.getIauthor()+"<br/>");
                out.println(book.getIprice()+"<br/>");
                if(book.getIcount()==0)
                {
                    out.println("<b>Hết hàng</b><br/>");
                    out.println("<img src="+blank_icon_path+" width=\"25\" height=\"25\" border=\"0\" />");
                }
                else
                {
                    out.println("<b>Còn hàng</b><br/>");
                    out.println("<img src="+book.getIimagepath()+" alt=\"Header image\" width=\"25\" height=\"25\" border=\"0\" />");
                }
                count++;
                out.println("</td>");
            }
            out.print("</tr>");
        }
    }
    /*<%for (int r = 0; r < 2; r++) {
    %>
    <tr id="item-container">
        <%
            for (int c = 0; c < 6; c++) {
        %>
        <td>TESTING</td>
        <%        }
        %>
    </tr>
    <%
        }
    %>*/
}
